package com.guofen.controller.name;

import com.guofen.dto.ModifyOrderInfo;
import com.guofen.dto.OrderInfoDTO;
import com.guofen.service.food.OrderInfoService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/orderInfo")
@Api(tags = "OrderInfoController", description = "UTA assignment")
public class OrderInfoController {

    @Autowired
    private OrderInfoService service;

    @ApiOperation("get order by status")
    @RequestMapping(value = "/getOrder",method = RequestMethod.POST)
    public Result getOrderByStatus(@RequestParam String[] status,
                                   @RequestParam(defaultValue = "8") Integer pageSize,
                                   @RequestParam(defaultValue = "1") Integer currentPage) {
        return ResultGenerator.genSuccessResult(service.getOrderByStatus(status, currentPage, pageSize));
    }

    @ApiOperation("delete order")
    @RequestMapping(value = "/deleteOrder",method = RequestMethod.POST)
    public Result deleteOrder(@RequestParam Integer orderId) {
        return ResultGenerator.genSuccessResult(service.deleteOrder(orderId));
    }

    @ApiOperation("add order")
    @RequestMapping(value = "/addOrder",method = RequestMethod.POST)
    public Result addOrder(@RequestBody OrderInfoDTO order) {
        return ResultGenerator.genSuccessResult(service.addOrder(order));
    }

    @ApiOperation("modify order")
    @RequestMapping(value = "/modifyOrder",method = RequestMethod.POST)
    public Result modifyOrder(@RequestBody ModifyOrderInfo modifyOrder) {
//        System.out.println(modifyOrder);
//        return ResultGenerator.genSuccessResult();
        return ResultGenerator.genSuccessResult(service.modifyOrder(modifyOrder.getOrderId(),
                modifyOrder.getMenu()));
    }

    @ApiOperation("process order")
    @RequestMapping(value = "/processOrder",method = RequestMethod.POST)
    public Result processOrder(@RequestParam Integer orderId,
                               @RequestParam Boolean pass) {
        return ResultGenerator.genSuccessResult(service.processOrder(orderId, pass));
    }

    @ApiOperation("get menu by order id")
    @RequestMapping(value = "/getMenu",method = RequestMethod.POST)
    public Result getMenu(@RequestParam Integer orderId) {
        return ResultGenerator.genSuccessResult(service.getMenu(orderId));
    }

    @ApiOperation("get customer orders")
    @RequestMapping(value = "/getCustomerOrder",method = RequestMethod.POST)
    public Result getCustomerOrder() {
        return ResultGenerator.genSuccessResult(service.getCustomerOrder());
    }
}
